// 请求
const request = require("request")

// ORM
const { Sequelize, INTEGER, STRING } = require('sequelize');
const sequelize = new Sequelize({
  host: 'localhost',
  dialect: 'sqlite',
  pool: {
    max: 5,
    min: 0,
    acquire: 30000,
    idle: 10000
  },
  storage: './wallpaper.sqlite',
  // operatorsAliases: false
});
// 文件
const ImageArchive = sequelize.define("image_archive", {
    id : {
        type: INTEGER,
        primaryKey: true,
        autoIncrement: true
    },
    folderName : STRING(100),
    fileName : STRING(100),
    copyright : STRING(200),
});

// 导入express
var express = require('express')

// 创建express服务器
var app = express()
// 静态资源目录
app.use(express.static('static'))

// 壁纸数据
app.get('/wallpaper.json', function (req, resp) {
    ImageArchive.sync().then(()=>{
        ImageArchive.findAll().then((res)=>{
            resp.send(res);
        })
    })
})
// 默认页面跳转
app.get('', function (req, resp) {
    resp.location('/wallpaper.html');
})
app.get('/', function(req, resp) {
    resp.location('/wallpaper.html');
})

// 端口绑定
app.listen(8030, ()=>{
    console.log('App listening at port 8030')
})